<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>下订单</title>
    <style>
        .errorInfo{
            color: red;
            font-size: 12px;
        }
    </style>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/util.js"></script>
    <script>
        let totalPrice;
        window.onload=function (){
            totalPrice = getQuery("totalPrice");
        }
        async function addOrder(){
            console.log($("name").value)
            console.log($("address").value)
            console.log($("phone").value)
            let info =await ajaxGet("/order/add",{
                receiver:$("name").value,
                address:$("address").value,
                phone:$("phone").value,
                orderMoney:totalPrice
            });
            if (info == "ok"){
                location.href="/html/custom/success.html";
            }
            else {
                let divArray = document.getElementsByClassName("errorInfo");
                for (let i = 0; i < divArray.length; i++) {
                    divArray[i].innerHTML="";
                }
                for (let i = 0; i < info.length; i++) {
                    let errorObj = info[i];
                    $(errorObj.field + "Div").innerHTML=errorObj.defaultMessage;
                }
            }
        }
    </script>
</head>
<body>

    <h2>请完善订单</h2>
    收货人：<input type="text" id="name">
    <div id="receiverDiv" class="errorInfo"></div>
    收获地址：<input type="text" id="address">
    <div id="addressDiv" class="errorInfo"></div>
    联系电话：<input type="text" id="phone">
    <div id="phoneDiv" class="errorInfo"></div>
<input type="button" value="提交订单" onclick="addOrder()">
</body>
</html>